<template>
	<view>
		<view class="content">
			<view class="order-title">
				<view v-for="(items, index) in titleList" :key="index" class="title-list" :class="current===items.index?'active':''"
				 @click="changeTitle(index)">{{ items.name }}</view>
			</view>
			<view class="opinion-content">
				<view v-for="(items, index) in list" :key="index" class="opinion-items">
					<view class="opinion-info">
						<view class="opinion-title">{{ opinionType(items.opinion_type) }}</view>
						<view class="opinion-date">{{ items.create_time }}</view>
					</view>
					<view class="opinion-icon">
						<image style="width: 100%; height: 100%;" mode="aspectFit" :src="icon.right"></image>
					</view>
				</view>
			</view>
			<view v-if="list.length">
				
			</view>
		</view>
		<view class="create-button" @click="handleCreat()">
			<view class="new-icon">
				<image style="width: 100%; height: 100%;" mode="aspectFit" :src="icon.new"></image>
			</view>
			<view class="new-name">新建</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: 0,
				titleList: [{
					name: '未回复',
					index: 0
				}, {
					name: '已回复',
					index: 1
				}],
				list: [],
				icon: {
					right: '/static/images/icons/icon_next@3x.png',
					new: '/static/images/icons/icon_new@3x.png'
				}
			}
		},
		created() {
			this.getList()
		},
		methods: {
			getList() {
				const path = {
					app: "wx",
					api: "api_wx_user_feedbackList",
					version: "1.0",
					type: 2,
					data: {
						is_answer: this.current
					}
				}
				this.sendSock(path)
			},
			changeTitle(index) {
				this.current = index;
				this.getList();
			},
			handleCreat(){
				const _this = this
				uni.navigateTo({
					url: '/pages/personal/feedback/detail?' + _this.version
				})
			},
			sendSock(path) {
				if (this.$store.state.socketOpen) {
					uni.sendSocketMessage({
						data: JSON.stringify(path)
					});
				} else {
					this.$store.state.socketMsgQueue.push(JSON.stringify(path));
				}
				const _this = this
				uni.onSocketMessage(function(res) {
					_this.getSock(res.data)
				});
			},
			getSock(res) {
				if (res !== '{"type":"ping"}') {
					const resj = JSON.parse(res);
					if (resj.code === -1) {
						uni.showToast({
							icon: "none",
							title: resj.message,
							duration: 2000
						});
					} else if (resj.code === 403) {
						const key = this.getUrlKey('key')
						this.getMess(key);
					} else {
						if (resj.api === "api_wx_user_login") {
							this.$store.commit('login', resj.data);
							console.log('key值登录', resj.data)
							this.temporary()
						} else if (resj.api === "api_wx_user_keepLogin") {
							this.$store.commit('login', resj.data);
							console.log('token登录', resj.data)
							this.temporary()
						} else if (resj.api === "api_wx_user_feedbackList") {
							this.list = resj.data
							console.log('this.list', this.list)
						}
					}
				}
			}
		}
	}
</script>

<style>
	page {
		background-color: #F5F5F5;
	}

	.content {
		padding: 0 30rpx;
	}

	.order-title {
		height: 132rpx;
		display: flex;
		align-items: center;
	}

	.title-list {
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: rgba(153, 153, 153, 1);
		line-height: 1;
		position: relative;
	}

	.order-title .title-list:not(:first-child) {
		margin-left: 40rpx;
	}

	.title-list.active {
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: rgba(51, 51, 51, 1);
		line-height: 1;
	}

	.title-list.active:after {
		content: "";
		display: table;
		width: 40rpx;
		height: 8rpx;
		background: rgba(255, 195, 36, 1);
		border-radius: 4rpx;
		position: absolute;
		left: calc(50% - 20rpx);
		bottom: -14rpx;
	}

	.opinion-items,
	.opinion-icon {
		display: flex;
		align-items: center;
	}

	.opinion-items {
		justify-content: space-between;
		width: 690rpx;
		height: 146rpx;
		background: rgba(255, 255, 255, 1);
		border-radius: 10rpx;
		padding: 0 36rpx 0 20rpx;
		box-sizing: border-box;
	}

	.opinion-content .opinion-items:not(:first-child) {
		margin-top: 30rpx;
	}

	.opinion-icon {
		width: 15rpx;
		height: 30rpx;

	}

	.opinion-title {
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: rgba(51, 51, 51, 1);
		line-height: 1;
	}

	.opinion-date {
		margin-top: 26rpx;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(178, 178, 178, 1);
		line-height: 1;
	}

	.create-button {
		width: 100%;
		height: 98rpx;
		background: rgba(250, 250, 250, 1);
		box-shadow: 0px 0px 30px 0px rgba(0, 0, 0, 0.1);
		position: fixed;
		bottom: 0;
	}

	.create-button {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.new-icon {
		width: 30rpx;
		height: 30rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.new-name{
		margin-left: 10rpx;
		font-size:30rpx;
		font-family:PingFang SC;
		font-weight:500;
		color:rgba(51,51,51,1);
		line-height:1;
	}
</style>
